angular.module('Push', [])
    .factory('Push', [
        'popup', '$timeout', 'httpService', '$rootScope',
        function(popup, $timeout, httpService, $rootScope) {
            var onGetRegistradionID, push;
            push = void 0;
            onGetRegistradionID = function(data) {
                var error1, exception, registrationId;
                try {
                    $rootScope.registrationId = registrationId = data;
                    httpService.query('accountCenter/saveregistrationid', {
                        registrationid: $rootScope.registrationId
                    }, 'GET').then(function(res) {
                        if (res.code === 200) {
                            console.log('registrationId: ' + registrationId);
                        } else {
                            console.log('registrationId: ' + res.data.msg);
                        }
                    });
                } catch (error1) {
                    exception = error1;
                    console.log('error registrationId:' + exception);
                }
            };
            return {
                init: function(notificationCallback) {
                    push = window.plugins && window.plugins.jPushPlugin;
                    if (push) {
                        window.plugins.jPushPlugin.init();
                        window.plugins.jPushPlugin.setDebugMode(true);
                        window.plugins.jPushPlugin.openNotificationInAndroidCallback = notificationCallback;
                        window.plugins.jPushPlugin.receiveNotificationIniOSCallback = notificationCallback;
                        window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
                        $timeout((function() {
                            window.plugins.jPushPlugin.getRegistrationID(onGetRegistradionID);
                        }), 8000);
                    }
                }
            };
        }
    ]);
